﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Text_Adventures
{
    public class Item
    {
        public string ID { get; set; }
        public string Name { get; set; }
        public int Def { get; set; }
        public int Atk { get; set; }
        public int HP { get; set; }
        public int MP { get; set; }
        public uint Cost { get; set; }
        public int Acc { get; set; }
        public int Eva { get; set; }

        public Item(StreamReader reader, string name)
        {
            string line = "";

            while (!((line = reader.ReadLine()).Equals(name))) ;

            this.Name = name;            

            while (!line.Equals("end"))
            {
                if (reader.EndOfStream)
                    break;
                if (!reader.EndOfStream && ((line = reader.ReadLine().ToLower().Trim()) != ""))
                {
                    switch (line)
                    {
                        case "id":
                            line = reader.ReadLine();
                            ID = line;
                            break;
                        case "restorehp":
                            line = reader.ReadLine();
                            HP = Convert.ToInt32(line);
                            break;
                        case "restoremp":
                            line = reader.ReadLine();
                            MP = Convert.ToInt32(line);
                            break;
                        case "damage":
                            line = reader.ReadLine();
                            Atk = Convert.ToInt32(line);
                            break;
                        case "defense":
                            line = reader.ReadLine();
                            Def = Convert.ToInt32(line);
                            break;
                        case "cost":
                            line = reader.ReadLine();
                            string[] money = line.Split(' ');
                            string currency = money[1];
                            int qtd = Convert.ToInt32(money[0]);
                            switch (currency)
                            {
                                case "silver":
                                    qtd *= 10;
                                    break;
                                case "gold":
                                    qtd *= 100;
                                    break;
                            }
                            break;
                        default:
                            break;
                    }
                }
            }

        }
    }
}
